package Comprehensive_01;

import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Random random = new Random();
        Scanner sc = new Scanner(System.in);
        int[][] scores = new int[5][];
        //添加每个班级的人数
        for (int i = 0; i < scores.length; ) {
            System.out.println("请输入第" + (i + 1) + "个班级的学生");
            int member = sc.nextInt();
            if (member > -1 && member < 101) {
                scores[i] = new int[member];
                System.out.println("添加成功");
                i++;
                continue;
            }
            System.out.println("人数不合法");
        }
        //添加学生成绩
        for (int i = 0; i < scores.length; i++) {
            for (int j = 0; j < scores[i].length; j++) {
                scores[i][j] = random.nextInt(101);
            }
        }
        System.out.println("第三个班级的最高分和最低分" + getHighestScore(scores[2]) + " " + getLowestScore(scores[2]));
        System.out.println("第三个班级的总分和平均分为：" + getClassScores(scores[2]) + " " + getAverageScore(scores[2]));
        System.out.println("当前学年的最高分和最低分为：" + getHighestScore(scores) + " " + getLowestScore(scores));
        System.out.println("当前学年的平均分为：" + getAverageScore(scores));
        System.out.println("低于平均分的学生一共有：" + getLowAverageStu(scores));
    }

    public static int getClassScores(int[] scores) {
        int sum = 0;
        for (int score : scores) {
            sum += score;
        }
        return sum;
    }

    public static int getHighestScore(int[][] scores) {
        int max = scores[0][0];
        for (int[] score : scores) {
            max = Math.max(max, getHighestScore(score));
        }
        return max;
    }

    public static int getHighestScore(int[] scores) {
        int max = scores[0];
        for (int score : scores) {
            max = Math.max(max, score);
        }
        return max;
    }

    public static int getLowestScore(int[] scores) {
        int min = scores[0];
        for (int score : scores) {
            min = Math.min(min, score);
        }
        return min;
    }

    public static int getLowestScore(int[][] scores) {
        int min = scores[0][0];
        for (int[] score : scores) {
            min = Math.min(min, getLowestScore(score));
        }
        return min;
    }

    public static double getAverageScore(int[][] scores) {
        int sum = 0;
        int member = 0;
        for (int[] score : scores) {
            sum += getClassScores(score);
            member += score.length;
        }
        return (double) sum / member;
    }

    public static double getAverageScore(int[] scores) {
        return (double) getClassScores(scores) / scores.length;
    }

    public static int getLowAverageStu(int[][] scores) {
        int count = 0;
        double avg = getAverageScore(scores);
        for (int[] score : scores) {
            for (int i : score) {
                if (i < avg) {
                    count++;
                }
            }
        }
        return count;
    }
}
